# -*- coding: utf-8 -*-
# @Time    : 2022/1/1 15:34
# @Author  : TangDagui
# @Email   : 3297364807@qq.com
# @File    : FiveTask.py
# @Software: PyCharm

fr = open("price2016.csv", "r").readlines()
fw = open("price2016out.csv", "w")
ls = []
for line in fr:
    line = line.replace("\n", "")  # 将换行符替换为""
    ls.append(line.split(","))  # 返回字符串中单词的列表，使用","作为分隔符字符串。并添加到列表中
for i in range(len(ls)):  # 循环列表
    for j in range(len(ls[i])):
        ls[i][j] = ls[i][j].replace(".", "")  # 将"."替换为""
        if ls[i][j].isnumeric():  # 判断是否全为数字
            ls[i][j] = "{:.2}%".format(float(ls[i][j]) / 1000)  # 因为前面将"."替换为"" 所以要除以1000

for row in ls:
    fw.write(",".join(
        row) + "\n")  # 连接任意数量的字符串 调用其方法的字符串插入每个给定字符串之间。结果作为新字符串返回。示例：'.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
fw.close()
